/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package atag.runtime.sensors;

import com.sun.spot.sensorboard.peripheral.*;
import com.sun.spot.sensorboard.EDemoBoard;
import com.sun.spot.sensorboard.io.IScalarInput;
import java.io.IOException;

/**
 *
 * @author mgowda
 */
public class Accelerometer implements ATaGSensor{

    private LIS3L02AQAccelerometer acc;

    public Accelerometer()
    {
        acc = (LIS3L02AQAccelerometer)EDemoBoard.getInstance().getAccelerometer();
    }
    
    void addIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who) 
    {
        acc.addIAccelerometer3DThresholdListener(who);
    }

    boolean areThresholdEventsEnabled(int axis)
    {
        return (acc.areThresholdEventsEnabled(axis));
    }

    void enableThresholdEvents(int axis, boolean enable)
    {
        acc.enableThresholdEvents(axis, enable);
    }
    public double getAccel()
    {
        double d=0;
        try {
            d=acc.getAccel();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return d;
    }

    public double getAccelZ()
    {
        double d=0;
        try {
            d=acc.getAccelZ();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return d;
    }

    public double getAccelY()
    {
        double d=0;
        try {
            d=acc.getAccelY();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return d;
    }
    public double getAccelX()
    {
        double d=0;
        try {
            d=acc.getAccelX();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return d;
    }

    int getCurrentScale()
    {
        return acc.getCurrentScale() ;
    }

    double[][] getGains()
    {
        return acc.getGains();
    }

    double getHighThreshold(int axis, boolean relative)
    {
        return acc.getHighThreshold(axis, relative);
    }

    IAccelerometer3DThresholdListener[] getIAccelerometer3DThresholdListeners()
    {
        return acc.getIAccelerometer3DThresholdListeners() ;
    }

    double getLowThreshold(int axis, boolean relative)
    {
        return acc.getLowThreshold(axis, relative) ;
    }

    double getRelativeAccel(){

        double relAccel=-1;
        try {
            relAccel=acc.getRelativeAccel();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return relAccel ;
    }

    double getRelativeAccelX()
    {
        double relAccelX=0;
        try {
            relAccelX=acc.getRelativeAccelX();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return relAccelX;
    }

    double getRelativeAccelY()
    {
        double relAccelY=0;
        try {
            relAccelY=acc.getRelativeAccelY();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return relAccelY;
    }

    double getRelativeAccelZ()
    {
        double relAccelZ=0;
        try {
            relAccelZ=acc.getRelativeAccelZ();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return relAccelZ;
    }

    void removeIAccelerometer3DThresholdListener(IAccelerometer3DThresholdListener who)
    {
        acc.removeIAccelerometer3DThresholdListener(who);
    }

    void reset()
    {
        acc.reset();
    }

    void setThresholds(int axis, double low, double high, boolean relative)
    {
        acc.setThresholds(axis, low, high, relative);
    }

    void setZeroOffsets(double[][] offs)
    {
        acc.setZeroOffsets(offs);
    }

    double getTilt(int axis)
    {
        double tilt=1080;
        try {
            tilt=acc.getTilt(axis);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return tilt ;
    }

    boolean supportsThresholdEvents()
    {
        return acc.supportsThresholdEvents() ;
    }

    void thresholdChanged(IScalarInput in, int low, int high)
    {
       acc.thresholdChanged(in, low, high);
    }

    void thresholdExceeded(IScalarInput in, int val)
    {
        acc.thresholdExceeded(in, val);
    }
}
